<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts' // echarts theme
import resize from '@/framework/utils/mixins/resize'
import processDetailApi from '@/framework/api/workflow/processOverview/index'

require('echarts/theme/macarons')

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null,
      keys: [],
      values: []
    }
  },
  mounted() {
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart(beginTime, endTime) {
      const params = {}
      params.beginTime = beginTime
      params.endTime = endTime
      processDetailApi.lineChart(params).then((res) => {
        this.chart = echarts.init(this.$el, 'macarons')
        const option = {
          xAxis: {
            type: 'category',
            data: res.data.keys,
            boundaryGap: false,
            axisTick: {
              show: false,
              alignWithLabel: true

            },
            axisLine: {
              lineStyle: {
                color: '#F5F6F9'
              }
            },
            axisLabel: {
              textStyle: {
                color: '#86909C'
              }
            }
          },
          yAxis: {
            type: 'value',
            splitArea: { show: false }, // , areaStyle: { 'color': ['#fff'] }
            splitLine: { // 去除网格线
              show: true,
              lineStyle: {
                color: '#E5E8EF',
                type: 'dashed'
              }
            },
            axisTick: {
              show: false
            },
            // 坐标轴字的颜色
            axisLabel: {
              textStyle: {
                color: '#86909C'
              }
            },
            // 设置左边线
            axisLine: {
              show: false,
              lineStyle: {
                color: '#86909C'
              // type: 'dotted'
              }
            }
          },
          series: [
            {
              type: 'line',
              data: res.data.values,
              animationDuration: 2800,
              animationEasing: 'quadraticOut',
              itemStyle: {
                normal: {
                  lineStyle: {
                    // color: '#3461FF'
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ // 1代表上面
                      offset: 0,
                      color: '#3461FF'
                    }, {
                      offset: 1,
                      color: '#3461FF'

                    }]),
                    width: 2
                  },
                  areaStyle: {
                    color: '#f3f8ff'
                  }
                }
              }
            }
          ],
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            },
            padding: [5, 10]
          },
          grid: {
            left: 30,
            right: 40,
            bottom: 20,
            top: 30,
            containLabel: true
          },
          splitLine: {
            lineStyle: {
              type: 'dashed' // y轴分割线类型
            }
          }
        }
        this.chart.setOption(option)
      })
    }
  }
}
</script>
